package ypmits.components.inputtext {
	import ypmits.components.Component;
	import ypmits.components.ComponentEvent;
	import ypmits.components.ComponentSkin;
	import ypmits.keyboard.Keyboard;
	import ypmits.setup.EasySetup;

	import flash.events.KeyboardEvent;
	import flash.text.TextField;

	/**
	 * @author Dave Lenz
	 */
	public class InputText extends Component {

		public function InputText( skin : ComponentSkin = null ) {
			super( skin );
			
			textfield = new TextField( );
			textfield.embedFonts = skin.embedFonts;
			textfield.antiAliasType = skin.antialiastype;
			textfield.gridFitType = skin.gridfittype;
			textfield.type = skin.type;
			textfield.selectable = true;
			textfield.setTextFormat( skin.format );
			textfield.defaultTextFormat = skin.format;
			textfield.multiline = false;
			textfield.wordWrap = false;
			textfield.border = false;
			textfield.borderColor = 0;
			textfield.background = true;
			textfield.multiline = false;
			textfield.wordWrap = false;
			textfield.backgroundColor = skin.backgroundcolor;
			textfield.width = skin.backgroundwidth;
			textfield.height = skin.backgroundheight;
			textfield.restrict = skin.restrict;
			textfield.filters = [ skin.filter ];
			textfield.text = skin.text;
			addChild( textfield );
			
			EasySetup.instance.stage.addEventListener( KeyboardEvent.KEY_DOWN, keyDownHandler );
		}

		
		private function keyDownHandler( e : KeyboardEvent) : void {
			if( e.keyCode == Keyboard.ENTER && (!(e.altKey || e.ctrlKey)) && e.target is TextField ) {
				if( textfield.text != "" ) {
					dispatchEvent( new ComponentEvent( ComponentEvent.ENTER ) );
				}
			}
		}
	}
}
